/*
 * Copyright 2011 ArcBees Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.arcbees.server.auth;

import javax.persistence.Id;

/**
 * A simple representation of user information for session. This is meant to be
 * stored inside a database.
 * 
 * @author Christian Goudreau
 */
public class UserSession {
  @Id
  private String cookie;
  private String userId;
  private Long timeout;

  public Long getTimeout() {
    return timeout;
  }

  public void setTimeout(Long timeout) {
    this.timeout = timeout;
  }

  public String getCookie() {
    return cookie;
  }

  public void setCookie(String cookie) {
    this.cookie = cookie;
  }

  public String getUserId() {
    return userId;
  }

  public void setUserId(String userId) {
    this.userId = userId;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((cookie == null) ? 0 : cookie.hashCode());
    result = prime * result + ((timeout == null) ? 0 : timeout.hashCode());
    result = prime * result + ((userId == null) ? 0 : userId.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    UserSession other = (UserSession) obj;
    if (cookie == null) {
      if (other.cookie != null) {
        return false;
      }
    } else if (!cookie.equals(other.cookie)) {
      return false;
    }
    if (timeout == null) {
      if (other.timeout != null) {
        return false;
      }
    } else if (!timeout.equals(other.timeout)) {
      return false;
    }
    if (userId == null) {
      if (other.userId != null) {
        return false;
      }
    } else if (!userId.equals(other.userId)) {
      return false;
    }
    return true;
  }
}
